package com.example.demo.controller;

import com.example.demo.properties.GirlProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class HelloController {

    @Value("${name}")
    private String name;

    @Value("${server.servlet.context-path}")
    private String path;

    @Autowired
    private GirlProperties girlProperties;

    @GetMapping("/path")
    public String path() {
        return "path is " + path;
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String hello(){
        return "Hello " + name;
    }

    @RequestMapping(value = {"/hi", "/hello"}, method = RequestMethod.POST)
    public String hi(){
        return "Hello World";
    }

    @RequestMapping(value = {"/hi"}, method = RequestMethod.GET)
    public String hiSomeOne(@RequestParam(value = "id", required = false, defaultValue = "0") Integer myId){
        return "Hello " + myId;
    }

    @GetMapping(value = "/prop")
    public String getProperty(){
        return girlProperties.getName() + " " + girlProperties.getAge();
    }

}
